<template>
  <div class="my-information">
    <!-- nav 导航栏 -->
    <van-nav-bar
      title="个人信息"
      right-text="保存"
      left-arrow
      @click-left="$router.back()"
      @click-right="onClickRight"
    />

    <!-- 用户头像 -->
    <van-cell is-link @click="isUpadtaPhotoShow = true" title="头像">
      <van-image class="avatar" fit="cover" round :src="user.user_photo" />
    </van-cell>

    <!-- 用户昵称 -->
    <van-cell
      is-link
      title="昵称"
      @click="isUpdataNameShow = true"
      :value="user.username"
    >
    </van-cell>

    <!-- 性别 -->
    <van-cell
      is-link
      title="性别"
      @click="isUpadtaSexShow = true"
      :value="user.user_sex === '0' ? '男' : '女'"
    >
    </van-cell>

    <!-- 生日 -->
    <van-cell
      is-link
      @click="isUpadtaBirthdayShow = true"
      title="生日"
      :value="user.user_birth"
    >
    </van-cell>

    <!-- 手机号 -->
    <van-cell>
      <template #title>
        <span class="custom-title">手机号码</span>&nbsp;
        <span class="iconfont iconask"></span>
      </template>
      <template #right-icon>
        <span>{{ user.user_phone }}</span>
      </template>
    </van-cell>

    <!-- 编辑昵称 -->
    <van-popup
      v-model="isUpdataNameShow"
      position="bottom"
      style="height: 100%"
    >
      <updata-name
        v-model="user.username"
        v-if="isUpdataNameShow"
        @close="isUpdataNameShow = false"
      ></updata-name>
    </van-popup>

    <!-- 编辑性别 -->
    <van-popup v-model="isUpadtaSexShow" position="bottom">
      <updata-sex
        v-model="user.user_sex"
        v-if="isUpadtaSexShow"
        @close="isUpadtaSexShow = false"
      ></updata-sex>
    </van-popup>

    <!-- 编辑生日 -->
    <van-popup v-model="isUpadtaBirthdayShow" position="bottom">
      <updata-birthday
        v-model="user.user_birth"
        v-if="isUpadtaBirthdayShow"
        @close="isUpadtaBirthdayShow = false"
      ></updata-birthday>
    </van-popup>

    <!-- 编辑头像 -->
    <van-popup
      v-model="isUpadtaPhotoShow"
      style="height: 100%"
      position="bottom"
    >
      <update-photo
        v-model="user.user_photo"
        v-if="isUpadtaPhotoShow"
        @close="isUpadtaPhotoShow = false"
      ></update-photo>
    </van-popup>
  </div>
</template>

<script>
import UpdataName from "./updata-name.vue";
import UpdataSex from "./updata-sex.vue";
import UpdataBirthday from "./updata-birthday.vue";
import UpdatePhoto from "./updata-photo.vue";
import { login } from "@/api/login";
import store from "@/store";

export default {
  name: "myInformation",
  components: {
    UpdataName,
    UpdataSex,
    UpdataBirthday,
    UpdatePhoto,
  },
  props: {},
  data() {
    return {
      // 用户表
      user: {},
      isUpdataNameShow: false,
      isUpadtaSexShow: false,
      isUpadtaBirthdayShow: false,
      isUpadtaPhotoShow: false,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.loadUserProfile();
  },
  mounted() {},
  methods: {
    // 获取用户信息
    async loadUserProfile() {
      try {
        const data = await login({ username: store.getters.username });
        // console.log(data);
        this.user = data[0];
        console.log(this.user);
      } catch (err) {
        this.$toast("获取用户信息失败");
      }
    },
    onClickRight() {
      this.$toast("保存成功");
      this.$router.back();
    },
  },
};
</script>
<style lang='less' scoped>
.van-nav-bar {
  margin-bottom: 5px;
}
/deep/ .van-nav-bar .van-icon {
  color: #000;
  font-size: 18px;
}
/deep/ .van-nav-bar__text {
  color: #000;
}
/deep/ .van-nav-bar__title {
  font-size: 18px;
  font-weight: 700;
}
.user_photo {
  width: 40px;
  height: 40px;
}
.avatar {
  width: 30px;
  height: 30px;
}
</style>
